package com.haoshuang.zhouzhoubang.ui.page.mine.wallet.frozen

import android.content.Context
import android.graphics.Color
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.databinding.ActivityFrozenAmountBinding
import com.haoshuang.zhouzhoubang.model.bean.DepositBean
import com.haoshuang.zhouzhoubang.ui.page.mine.wallet.frozen.record.FrozenAmountRecordActivity
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.clickWithTrigger
import com.mufeng.libs.utils.view.gone
import com.mufeng.libs.utils.view.visible
import java.math.BigDecimal

/**
 *  冻结金额
 */
class FrozenAmountActivity : BaseVMActivity<FrozenAmountViewModel, ActivityFrozenAmountBinding>() {

    companion object {
        fun launch(context: Context){
            context.startPage<FrozenAmountActivity>()
        }
    }
    var list = arrayListOf<DepositBean>()
    lateinit var adapter: ForzenAdapter2
    var is_deposit = 1
    override fun initView(savedInstanceState: Bundle?) {
        binding.titleBar.title = "冻结金额"
        binding.titleBar.leftImageView().click { finish() }

        adapter = ForzenAdapter2(list)
        adapter.setOnItemClickListener { adapter, view, position ->
            startPage<FrozenAmountRecordActivity>(
                "fcate_id" to list[position].fcate_id,
                "is_team" to is_deposit,
                "is_deposit" to "3",
                "ids" to team_id,
                "price" to list[position].money,
                "service_id" to list[position].id.toString()
            )
        }
        binding.rvList.layoutManager = LinearLayoutManager(this)
        binding.rvList.adapter = adapter

        binding.tvNext.clickWithTrigger {
            /*   XPopup.Builder(this@FrozenAmount2Activity)
                   .asCustom(TxDialog(this@FrozenAmount2Activity) {
                       startPage<BondNewActivity2>()
                   })
                   .show()*/
        }
    }

    override fun initData() {
    }

    override fun onResume() {
        super.onResume()
        vm.getWalletDetail()
        vm.getDepositList(is_deposit)
    }

    override fun startObserve() {
        vm.getDepositListData.observeState(this) {
            onLoading { showLoading() }
            onError { code, msg ->
                dismissLoading()
                toast(msg)
            }
            onSuccess {
                dismissLoading()
                list.clear()
                list.addAll(it?.data ?: listOf())

                adapter.notifyDataSetChanged()
            }
        }
        vm.getWalletDetailData.observeState(this) {
            onLoading { }
            onError { code, msg ->
                dismissLoading()
                toast(msg)
            }
            onSuccess {
                dismissLoading()
                var bd = BigDecimal(it?.data?.frozen_money)
                var value = bd.setScale(2, BigDecimal.ROUND_HALF_UP)
                binding.tvPrice.setText(value.toString())
            }
        }
    }

}